#include "EquationSolver.h"
using namespace std;

class Function1 : public Function
{
public:
    double operator()(double _x)
    {
        double f;
        f = 1 / _x - tan(_x);
        return f;
    }
};

class Function2 : public Function
{
public:
    double operator()(double _x)
    {
        double f;
        f = 1 / _x - pow(2, _x);
        return f;
    }
};

class Function3 : public Function
{
public:
    double operator()(double _x)
    {
        double f;
        f = pow(2,-_x) + exp(_x) + 2*cos(_x) - 6;
        return f;
    }
};

class Function4 : public Function
{
public:
    double operator()(double _x)
    {
        double f;
        f = (pow(_x,3) + 4*pow(_x,2) + 3*_x + 5)/(2*pow(_x,3) - 9*pow(_x,2) + 18*_x - 2);
        return f;
    }
};

int main(int argc,char *argv [ ]){
    cout << "B:" << endl;
    Function1 func1;
    Function2 func2;
    Function3 func3;
    Function4 func4;
    Bisection Bisec1(0, M_PI/2, eps, 100, func1);
    Bisection Bisec2(0, 1, eps, 100, func2);
    Bisection Bisec3(1, 3, eps, 100, func3);
    Bisection Bisec4(0, 4, eps, 100, func4);
    double root1 = Bisec1.solve(), root2 = Bisec2.solve(), root3 = Bisec3.solve(), root4 = Bisec4.solve();
    cout << "The roots of the four functions are: " << root1 << ' ' << root2 << ' ' << root3 << ' ' << root4 << endl;
    cout << "The corresponding f(c) is: " << func1(root1) << ' ' << func2(root2) << ' ' << func3(root3) << ' ' << func4(root4) << endl;
    return 0;
}
